package com.shop2cn.iapi.grouponmgr.testcase;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.google.gson.JsonObject;
import com.shop2cn.iapi.grouponmgr.parameter.ProductPriceChangeBean;
import com.shop2cn.iapi.grouponmgr.parameter.SaveGrouponReq;
import com.shop2cn.iapi.grouponmgr.service.ProductPriceChangeCall;
import com.shop2cn.iapi.agentproducts.parameter.AddAgentProductBean;
import com.shop2cn.iapi.agentproducts.parameter.ModifyAgentProductBean;
import com.shop2cn.iapi.agentproducts.parameter.ProductDetailsDto;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.business.service.AddAgentProductCallService;
import com.ymttest.business.service.Shop2cnGrouponCallService;
import com.ymttest.business.service.shenqi.GodmchManageCallService;
import com.ymttest.utils.YMTDateUtil;
/**
*接收商品改价反馈Test
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_ProductPriceChange{
	private static ProductPriceChangeBean productpricechangeBean;
	private static ProductPriceChangeCall productpricechangeCall;
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("接收商品改价反馈Test");
	}

	@Before
	public void caseUp() {
		productpricechangeBean=new ProductPriceChangeBean();
		productpricechangeCall=new ProductPriceChangeCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(productpricechangeCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_ProductPriceChange_001() {
		Logger.start(true,"正确数据，成功");
		try {

			Integer mchId = GodmchManageCallService.CreateSellerMch();
			AddAgentProductBean addAgentProductBean = AddAgentProductCallService.initAddAgentProduct(mchId, "AutoTest",
					false);
			String pid = AddAgentProductCallService.AddAgentProduct(addAgentProductBean);
			List<String> catalogList = new ArrayList<String>();
			ProductDetailsDto selectProductDetails = AddAgentProductCallService.selectProductDetails(mchId, pid);
			selectProductDetails.getCatalogList().forEach(a -> {
				catalogList.add(a.getCatalogId());
			});

			SaveGrouponReq savegrouponBean = Shop2cnGrouponCallService.initSaveGrouponReq(mchId, pid,
					catalogList.get(0), 100d);
			savegrouponBean.setBeginTime(YMTDateUtil.getBeforeOrNextDay(1, "yyyy-MM-dd HH:mm:ss"));
			savegrouponBean.setEndTime(YMTDateUtil.getBeforeOrNextDay(3, "yyyy-MM-dd HH:mm:ss"));
			Integer grouponProductId = Shop2cnGrouponCallService.SaveGrouponCall(savegrouponBean);

//			ModifyAgentProductBean initModifyAgentProductBean = AddAgentProductCallService.initModifyAgentProductBean(pid, addAgentProductBean);
//			AddAgentProductCallService.modifyAgentProduct(initModifyAgentProductBean);
			savegrouponBean.getGrouponCatalogs().get(0).setGrouponPrice(new BigDecimal(200));;
			savegrouponBean.setGrouponProductId(grouponProductId);
			Integer grouponProductId1 = Shop2cnGrouponCallService.SaveGrouponCall(savegrouponBean);
			
			
			
			
			productpricechangeBean.setUserId(mchId);
			productpricechangeBean.setProductId(pid);
			productpricechangeCall.setData(productpricechangeBean);
			productpricechangeCall.callService();
			Logger.verifyEquals("ok",productpricechangeCall.getReturnData(), "验证code");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}